package org.cagt.standard;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import org.cagt.Deck;

/**
 * Static class distributing various standard decks.
 * 
 * @author konrad.szalkowski (at) gmail.com
 * 
 */
public class StandardDecks {
	private StandardDecks() {
	}

	private static class PrimitiveDeck extends Deck<StandardCard> {
		protected PrimitiveDeck(Collection<? extends StandardCard> initializer) {
			super(initializer);
		}
	}

	/**
	 * Provides standard 52 decks of standard cards, connected together.
	 */
	public static Deck<StandardCard> get52DecksCollected(int numberOfDecks) {
		Set<StandardCard> cards = new HashSet<StandardCard>();
		for (int i = 0; i < numberOfDecks; i++) {
			for (Color color : Color.values()) {
				for (Figure figure : Figure.values()) {
					if (figure == Figure.Joker) {
						continue;
					}
					cards.add(new StandardCard(color, figure, i));
				}
			}

		}
		return new PrimitiveDeck(cards);
	}

	/**
	 * Provides 52 deck of standard cards with jokers (one for each card color).
	 */
	public static Deck<StandardCard> get52DeckWithJokers() {
		Set<StandardCard> cards = new HashSet<StandardCard>();
		for (Color color : Color.values()) {
			for (Figure figure : Figure.values()) {
				cards.add(new StandardCard(color, figure));
			}
		}
		return new PrimitiveDeck(cards);
	}

	/**
	 * Provides standard 52 deck of standard cards.
	 */
	public static Deck<StandardCard> get52Deck() {
		return get52DecksCollected(1);
	}

	/**
	 * Provides 24 deck of standard cards upper figures from 9 - King with Aces.
	 */
	public static Deck<StandardCard> get24Deck() {
		Set<StandardCard> cards = new HashSet<StandardCard>();
		for (Color color : Color.values()) {
			for (Figure figure : Figure.values()) {
				if (figure.ordinal() < 9 && figure != Figure.Ace) {
					continue;
				}
				cards.add(new StandardCard(color, figure));
			}
		}
		return new PrimitiveDeck(cards);
	}
}
